package xipai;

import javax.swing.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;

class Card{
    public String rank;//点数
    public String suit;//花色
    public Card(String rank,String suit){
        this.rank=rank;
        this.suit=suit;
    }

    @Override
    public String toString() {
        return "("+suit+rank+")";
    }
}

public class Test1 {
    public static ArrayList<Card> createArrayList() {
        ArrayList<Card> arrayList=new ArrayList<>();
        String[] suits={"♥","♠","♣","♦"};
        for (String suit:suits){
            for (int i=1;i<=10;i++){
                Card card=new Card(""+i,suit);
                arrayList.add(card);
            }
            arrayList.add(new Card("J",suit));
            arrayList.add(new Card("Q",suit));
            arrayList.add(new Card("K",suit));
            arrayList.add(new Card("A",suit));
        }
        return arrayList;
    }

    public static void main(String[] args) {
       ArrayList<Card> deck =createArrayList();
        System.out.println(deck);
        //洗牌
        Collections.shuffle(deck);
        System.out.println(deck);
        ArrayList<ArrayList<Card>> players=new ArrayList<>();
        for (int i=0;i<3;i++){
            players.add(new ArrayList<>());//向其中添加3个空的ArrayList对象
        }
        for (int round=0;round<5;round++){
            for (int j=0;j<3;j++){
                //从牌库中移除第一张牌并赋值给card
                Card card=deck.remove(0);
                //将card添加到对应的ArrayList中
                ArrayList<Card> player=players.get(j);
                player.add(card);
            }
        }
        //打印每个玩家的牌
        for (int i=0;i<3;i++){
            ArrayList<Card> player=players.get(i);
            System.out.println("玩家"+(i+1)+"的牌是："+player);
        }
    }
}
